package cn.com.qtgl.sso.oidc.comp.aop;

import cn.com.qtgl.sso.oidc.comp.interceptor.AppendAccessTokenInterceptor;
import cn.com.qtgl.sso.oidc.comp.interceptor.AppendTenantInterceptor;
import cn.melonlib.apis.support.annos.AppendTenant;
import cn.melonlib.cores.aop.anno.AppendAccessToken;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import javax.annotation.Resource;

@Configuration
public class OidcInterceptorAnnotationConfig {


    @Resource
    @Lazy
    private AppendAccessTokenInterceptor appendAccessTokenInterceptor;

    @Resource
    @Lazy
    private AppendTenantInterceptor appendTenantInterceptor;

    @Bean
    public DefaultPointcutAdvisor appendAccessToken(){
        AnnotationMatchingPointcut pointcut=new AnnotationMatchingPointcut(AppendAccessToken.class,true);
        DefaultPointcutAdvisor defaultPointcutAdvisor=new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setPointcut(pointcut);
        defaultPointcutAdvisor.setAdvice(appendAccessTokenInterceptor);
        return defaultPointcutAdvisor;
    }

    @Bean
    public DefaultPointcutAdvisor appendTenant(){
        AnnotationMatchingPointcut pointcut=new AnnotationMatchingPointcut(AppendTenant.class,true);
        DefaultPointcutAdvisor defaultPointcutAdvisor=new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setPointcut(pointcut);
        defaultPointcutAdvisor.setAdvice(appendTenantInterceptor);
        return defaultPointcutAdvisor;
    }
}
